package com.cudex.negocio.utils;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class ConnectionFactory {

	private static Connection connection = null;

	public Connection getConnection() throws NamingException {
		System.out.println("getConnection()");
		if (connection == null) {

			DataSource ds = null;
			Context initCtx = new InitialContext();

			ds = (DataSource) initCtx.lookup("java:cudexDS");
			try {
				connection = ds.getConnection();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return connection;
	}
}
